angular.module('start.common.cityselect.ctrl', [])

.controller('CitySelectCtrl', function($scope, $rootScope, $ionicScrollDelegate, $ionicHistory, $$CityService, $timeout, $http, $ionicLoading) {
    console.log("CitySelectCtrl");

    // 获取服务器 城市列表
    $$CityService.getcitys().success(function(data) {
        console.log(data);
    });

    $scope.DZM = "A";
    $scope.showDZM = false;
    $scope.cityZM = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
    $scope.zmHeight = ($rootScope.config.appHeight - 44) / $scope.cityZM.length;

    $scope.cityList = $$CityService.cityList();

    // 获取服务器 城市列表
    $$CityService.getcitys().success(function(data) {
        $scope.cityList = data.result;
    });
    // 选择城市
    $scope.selectCity = function(index) {
        $rootScope.config.city = $scope.cityList[index];
        $rootScope.config.city.set = true;
        $ionicLoading.show({
            template: $rootScope.config.city.name,
            noBackdrop: true
        });
        $timeout(function() {
            $ionicLoading.hide();
            $rootScope.$ionicGoBack();
            // $ionicHistory.clearHistory();
        }, 600);
    };

    // 点击右侧字母
    $scope.zmScollH = 0;
    $scope.zmClick = function(zm) {
        $scope.DZM = zm;
        if ($("#zm" + zm).offset().top != 0) {
            $scope.zmScollH = $scope.zmScollH + $("#zm" + zm).offset().top - 44;
            $ionicScrollDelegate.scrollTo(0, $scope.zmScollH, true);
        }
        $scope.showDZM = true;
        $timeout(function() {
            $scope.showDZM = false;
        }, 1500);
    };


});
